package com.controllers
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.KeyboardEvent;

	public class KeyboardController extends EventDispatcher
	{
		private var _keyDowFun:Function;
		private var _keyUpFun:Function;
		public function KeyboardController(target:IEventDispatcher=null)
		{
			super(target);
			target.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			target.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
			_keyDowFun = new Function;
			_keyUpFun = new Function;
		}
		public function init(display:IEventDispatcher):void{
			display.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
			display.addEventListener(KeyboardEvent.KEY_UP,onKeyUp);
		}
		
		public function set keyDownFun(fun:Function):void{
			_keyDowFun = fun;
		}
		public function set keyUpFun(fun:Function):void{
			_keyUpFun = fun;
		}		
		protected function onKeyDown(e:KeyboardEvent):void{
			_keyDowFun();
		}
		protected function onKeyUp(e:KeyboardEvent):void{
			_keyUpFun();	
		}
	}
}